package com.my.auth.security.configuration;

import com.my.auth.common.AuthConstants;
import com.my.auth.security.filter.BcloudFilterChainProxy;
import com.my.auth.security.filter.LoginFilter;
import com.my.auth.security.filter.LoginOutFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import javax.servlet.Filter;
import java.util.LinkedList;
import java.util.List;

/**
 * @author zhaodongchao
 * @date 2020/3/29 17:00
 **/
@Configuration
public class SecurityFilterChainConfiguration {
    @Bean(name = AuthConstants.DEFAULT_FILTER_NAME)
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public Filter filter(){
        return new BcloudFilterChainProxy( loadFilters());
    }

    private List<Filter> loadFilters() {
        List<Filter> filters = new LinkedList<>();
        LoginFilter loginFilter = new LoginFilter();
        filters.add(loginFilter);

        LoginOutFilter loginOutFilter = new LoginOutFilter();
        filters.add(loginOutFilter);
        return filters ;
    }
}
